---
title: "Local Authority RUC"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
# Data Tidying
library(tidyverse)
library(readr)
library(janitor)
# Working with Spatial Data
library(sf)
library(rmapshaper)
# Embedding HTML Widgets
library(htmltools)
library(DT)
library(leaflet)
library(crosstalk)
```
```{r data-tidying, include = F}
# Import LA .shp file and LA ruc
LA_shp <- st_read("Data/Local_Authority_Districts_(December_2011)_Boundaries_EW_BFC.shp") %>%
rmapshaper::ms_simplify()
LA_ruc <- read_csv("Data/RUC_LAD_2011_EN_LU.csv") %>%
clean_names() %>%
select(lad11cd, ruc11, broad_ruc11) %>%
mutate(ruc11 = factor(ruc11, levels = c("Mainly Rural (rural including hub towns >=80%)",
"Largely Rural (rural including hub towns 50-79%)",
"Urban with Significant Rural (rural including hub towns 26-49%)",
"Urban with City and Town",
"Urban with Minor Conurbation",
"Urban with Major Conurbation")),
broad_ruc11 = factor(broad_ruc11, levels = c("Predominantly Rural",
"Urban with Significant Rural",
"Predominantly Urban")))
LA_ruc_shp <- left_join(LA_shp, LA_ruc, by = "lad11cd") %>%
st_transform(4326) %>% # Convert from a UK Projection (epsg = 27700) to a Global Projection (epsg = 4326)
mutate(st_areasha = scales::comma(st_areasha / 1000000, accuracy = 1)) %>%
select(lad11cd, lad11nm, ruc11, broad_ruc11, st_areasha)
# Create shared dataset for CrossTalk HTML Widgets to communicate
shared_data <- crosstalk::SharedData$new(LA_ruc_shp)
```
Column {data-width=500}
-----------------------------------------------------------------------
### Map of Local Authorities in England, by 2011 Rural Classification
```{r leaflet-plot}
# plot leaflet choropleth
palette <- c("#003300", "#00FF00", "#CCCCCC", "#00CCFF", "#3366FF", "#0000FF")
factpal <- colorFactor(palette, LA_ruc_shp$ruc11)
labels <- sprintf(
"%s
%s",
LA_ruc_shp$lad11nm, LA_ruc_shp$ruc11
) %>% lapply(htmltools::HTML)
shared_data %>%
leaflet(options = leafletOptions(minZoom = 6)) %>%
addTiles() %>%
addPolygons(
stroke = T,
smoothFactor = 1,
fillOpacity = 0.7,
fillColor = ~factpal(ruc11),
color = "white",
weight = 2,
dashArray = "1",
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
setMaxBounds( lng1 = -7.1894561 # 56.374987 , -7.1894561
, lat1 = 56.374987
, lng2 = 3.9726560 # 50.002090 , 3.9726560
, lat2 = 49 )
# Found Coordinates using https://gridreferencefinder.com/#gr=TF3682097955|Point_s_A|1,NL7974532393|Point_s_C|1&ll=58.872857|-10.283202|Point_s_B|1,50.339852|4.3945353|Point_s_D|1,49.888972|7.7519529|Point_s_E|1,50.002090|3.9726560|Point_s_F|1
```
Column {data-width=500}
-----------------------------------------------------------------------
### 2011 Local Authorities
```{r Datatable}
shared_data %>%
DT::datatable(colnames = c("LA Code 2011", "LA Name", "Rural Classification (RUC)", "Broad RUC", "Area (km^2)", "Geometry"),
rownames = F,
options = list(scrollY = "70vh",
pageLength = 10,
scroller = TRUE,
columnDefs = list(
list(
visible = FALSE,
targets = 5
)
)
)
)
```
### Filters
```{r filters}
filter_select(
id = "lad11nm",
label = "Local Authority",
sharedData = shared_data,
group = ~lad11nm
)
```